#include "font_mgr.hpp"

#include "fonts/fonts.hpp"
#include "pointers.hpp"
#include "renderer.hpp"
#include "thread_pool.hpp"

namespace big
{
	font_mgr::font_mgr(std::vector<std::pair<float, ImFont**>> extra_font_sizes) :
	    m_extra_font_sizes(extra_font_sizes),
	    m_require_extra(eAlphabetType::LATIN),
	    m_fonts({
	        {eAlphabetType::CHINESE, {"msyh.ttc", "msyh.ttf", "arial.ttf"}},
	        {eAlphabetType::CYRILLIC, {"msyh.ttc", "msyh.ttf", "arial.ttf"}},
	        {eAlphabetType::JAPANESE, {"msyh.ttc", "msyh.ttf", "arial.ttf"}},
	        {eAlphabetType::KOREAN, {"malgun.ttf", "arial.ttf"}},
	        {eAlphabetType::TURKISH, {"msyh.ttc", "msyh.ttf", "arial.ttf"}},
	    })
	{
	}

	bool font_mgr::can_use()
	{
		return m_update_lock.try_lock();
	}

	void font_mgr::release_use()
	{
		m_update_lock.unlock();
	}

	void font_mgr::update_required_alphabet_type(eAlphabetType type)
	{
		m_require_extra = type;

		g_thread_pool->push([this] {
			rebuild();
		});
	}

	void font_mgr::rebuild()
	{
		m_update_lock.lock();

		g_renderer.pre_reset();

		auto& io = ImGui::GetIO();
		io.Fonts->Clear();

		const auto required_alphabet_types = get_required_alphabet_types();

		for (auto [size, font_ptr] : m_extra_font_sizes)
		{
			ImFontConfig fnt_cfg{};
			fnt_cfg.FontDataOwnedByAtlas = false;
			strcpy(fnt_cfg.Name, std::format("Fnt{}px", (int)size).c_str());

			const auto tmp_ptr = io.Fonts->AddFontFromMemoryTTF(const_cast<uint8_t*>(font_storopia),
			    sizeof(font_storopia),
			    size,
			    &fnt_cfg,
			    io.Fonts->GetGlyphRangesDefault());
			if (font_ptr)
			{
				*font_ptr = tmp_ptr;
			}

			for (const auto required_type : required_alphabet_types)
			{
				const auto font_file   = get_available_font_file_for_alphabet_type(required_type);
				const auto glyph_range = get_imgui_alphabet_type(required_type);
				if (required_type != eAlphabetType::LATIN && font_file.exists())
				{
					fnt_cfg.MergeMode = true;
					io.Fonts->AddFontFromFileTTF(font_file.get_path().string().c_str(), size, &fnt_cfg, glyph_range);
				}
			}
			io.Fonts->Build();
		}

		// icons blueh
		{
			ImFontConfig font_icons_cfg{};
			font_icons_cfg.FontDataOwnedByAtlas = false;
			std::strcpy(font_icons_cfg.Name, "Icons");
			g.window.font_icon = ImGui::GetIO().Fonts->AddFontFromMemoryTTF(const_cast<uint8_t*>(font_icons), sizeof(font_icons), 24.f, &font_icons_cfg);
		}

		g_renderer.post_reset();

		m_update_lock.unlock();
	}

	file font_mgr::get_available_font_file_for_alphabet_type(const eAlphabetType type) const
	{
		static const auto fonts_folder = std::filesystem::path(std::getenv("SYSTEMROOT")) / "Fonts";

		const auto& fonts = m_fonts.find(type);
		if (fonts == m_fonts.end())
			return {};
		for (const auto& font : fonts->second)
		{
			auto font_file = file(fonts_folder / font);
			if (font_file.exists())
			{
				return font_file;
			}
		}
		return {};
	}

	const std::unordered_set<eAlphabetType> font_mgr::get_required_alphabet_types() const
	{
		auto required_alphabet_types = std::unordered_set<eAlphabetType>({eAlphabetType::LATIN});

		required_alphabet_types.insert(get_game_language_alphabet_type());
		required_alphabet_types.insert(m_require_extra);

		return required_alphabet_types;
	}

	eAlphabetType font_mgr::get_game_language_alphabet_type()
	{
		switch (*g_pointers->m_gta.m_language)
		{
		case eGameLanguage::RUSSIAN: return eAlphabetType::CYRILLIC;
		case eGameLanguage::JAPANESE: return eAlphabetType::JAPANESE;
		case eGameLanguage::KOREAN: return eAlphabetType::KOREAN;
		case eGameLanguage::SIMPLIFIED_CHINESE:
		case eGameLanguage::TRADITIONAL_CHINESE: return eAlphabetType::CHINESE;
		}
		return eAlphabetType::LATIN;
	}

	const ImWchar* font_mgr::get_imgui_alphabet_type(const eAlphabetType type)
	{
		auto& io = ImGui::GetIO();
		switch (type)
		{
		case eAlphabetType::CHINESE: return GetGlyphRangesChineseSimplifiedOfficial();
		case eAlphabetType::CYRILLIC: return io.Fonts->GetGlyphRangesCyrillic();
		case eAlphabetType::JAPANESE: return io.Fonts->GetGlyphRangesJapanese();
		case eAlphabetType::KOREAN: return io.Fonts->GetGlyphRangesKorean();
		case eAlphabetType::TURKISH: return GetGlyphRangesTurkish();

		default:
		case eAlphabetType::LATIN: return io.Fonts->GetGlyphRangesDefault();
		}
	}

	const ImWchar* font_mgr::GetGlyphRangesChineseSimplifiedOfficial()
	{
		// Store all official characters for Simplified Chinese.
		// Sourced from https://en.wikipedia.org/wiki/Table_of_General_Standard_Chinese_Characters
		// (Stored as accumulative offsets from the initial unicode codepoint 0x4E00. This encoding is designed to helps us compact the source code size.)
		static const short accumulative_offsets_from_0x4E00[] = {0, 1, 2, 4, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 3, 2, 1, 1, 1, 3, 1, 2, 3, 2, 2, 4, 1, 1, 1, 2, 1, 4, 1, 2, 3, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 2, 2, 1, 3, 1, 1, 1, 1, 1, 5, 3, 7, 1, 2, 11, 4, 4, 2, 1, 2, 1, 2, 1, 2, 1, 1, 1, 1, 3, 1, 1, 1, 3, 1, 2, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 4, 1, 2, 1, 4, 5, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 3, 2, 1, 1, 1, 1, 1, 1, 5, 1, 2, 2, 1, 1, 3, 2, 1, 1, 4, 2, 3, 1, 1, 4, 2, 2, 2, 8, 1, 3, 1, 1, 1, 1, 6, 1, 1, 1, 1, 3, 1, 1, 2, 2, 1, 1, 1, 3, 1, 4, 1, 4, 2, 2, 2, 2, 1, 6, 3, 1, 1, 5, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 4, 3, 3, 1, 3, 2, 1, 5, 1, 2, 1, 4, 1, 2, 2, 1, 2, 2, 2, 2, 3, 2, 1, 1, 3, 2, 3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 1, 23, 7, 8, 35, 26, 5, 23, 9, 5, 32, 5, 3, 1, 1, 1, 3, 1, 1, 1, 3, 2, 1, 2, 1, 3, 6, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 3, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 3, 3, 1, 1, 2, 3, 2, 1, 1, 1, 1, 3, 1, 1, 1, 1, 2, 3, 1, 1, 1, 3, 3, 4, 10, 1, 21, 18, 11, 2, 19, 4, 30, 4, 15, 2, 61, 5, 11, 24, 27, 7, 28, 5, 5, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 2, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 4, 2, 1, 2, 1, 1, 2, 6, 2, 1, 2, 1, 1, 1, 1, 1, 2, 3, 6, 3, 1, 2, 3, 5, 1, 3, 7, 1, 4, 6, 2, 6, 1, 15, 3, 3, 1, 1, 1, 5, 1, 9, 1, 1, 2, 3, 4, 3, 1, 1, 1, 1, 1, 2, 3, 2, 1, 1, 1, 5, 12, 1, 2, 13, 2, 1, 2, 3, 6, 7, 2, 10, 3, 10, 2, 3, 3, 6, 2, 1, 1, 5, 1, 1, 15, 2, 3, 4, 13, 8, 1, 3, 1, 1, 2, 1, 1, 1, 1, 1, 1, 3, 9, 1, 1, 1, 3, 1};
		static ImWchar base_ranges[] = // not zero-terminated
		    {
		        0x0020,
		        0x00FF, // Basic Latin + Latin Supplement
		        0x3000,
		        0x30FF, // Punctuations, Hiragana, Katakana
		        0x31F0,
		        0x31FF, // Katakana Phonetic Extensions
		        0xFF00,
		        0xFFEF, // Half-width characters
		    };
		static ImWchar full_ranges[IM_ARRAYSIZE(base_ranges) + IM_ARRAYSIZE(accumulative_offsets_from_0x4E00) * 2 + 1] = {0};
		if (!full_ranges[0])
		{
			memcpy(full_ranges, base_ranges, sizeof(base_ranges));
			ImWchar* out_ranges = full_ranges + IM_ARRAYSIZE(base_ranges);
			int base_codepoint  = 0x4E00;
			for (int n = 0; n < IM_ARRAYSIZE(accumulative_offsets_from_0x4E00); n++, out_ranges += 2)
			{
				out_ranges[0] = out_ranges[1] = (ImWchar)(base_codepoint + accumulative_offsets_from_0x4E00[n]);
				base_codepoint += accumulative_offsets_from_0x4E00[n];
			}
			out_ranges[0] = 0;
		}
		return &full_ranges[0];
	}

	const ImWchar* font_mgr::GetGlyphRangesTurkish()
	{
		static const ImWchar icons_ranges_Turkish[] = {
		    0x0020,
		    0x00FF, // Basic Latin + Latin Supplement
		    0x00c7,
		    0x00c7, // Ç
		    0x00e7,
		    0x00e7, // ç
		    0x011e,
		    0x011e, // Ğ
		    0x011f,
		    0x011f, // ğ
		    0x0130,
		    0x0130, // İ
		    0x0131,
		    0x0131, // ı
		    0x00d6,
		    0x00d6, // Ö
		    0x00f6,
		    0x00f6, // ö
		    0x015e,
		    0x015e, // Ş
		    0x015f,
		    0x015f, // ş
		    0x00dc,
		    0x00dc, // Ü
		    0x00fc,
		    0x00fc, // ü
		    0,
		};
		return &icons_ranges_Turkish[0];
	}
}
